#include "StdAfx.h"
#include "ZObject.h"


mapStrFun* ZObject::m_pClassDynCreateMap = NULL;

ZObjectInfo::ZObjectInfo( const QString& sType, ZCreateObjectFunPtr pFun )
{
	if(NULL == ZObject::m_pClassDynCreateMap)
	{
		ZObject::m_pClassDynCreateMap = new mapStrFun();
	}

	auto i = ZObject::m_pClassDynCreateMap->find(sType);
	if (i == ZObject::m_pClassDynCreateMap->end())
	{
		(*ZObject::m_pClassDynCreateMap)[sType] = pFun;
	}
	else
	{
		i->second = pFun;
	}
}

ZObject* ZObject::CreateObjFromName( const QString& sClassName )
{
	ZCreateObjectFunPtr funPtr = (*m_pClassDynCreateMap)[sClassName];
	if (NULL != funPtr)
	{
		return funPtr();
	}

	return NULL;
}

ZObject* ZObject::ZCreateObj()
{
	return CreateObjFromName(GetClassName_Z());
}
